extends Card


func play_on_release(card_view: CardView) -> void:
	var monster_handler = card_view.get_tree().get_first_node_in_group("monster_handler")
	var player = card_view.get_tree().get_first_node_in_group("player")
	player.play_animation("attack")
	var monsters = monster_handler.get_children()
	for monster in monsters:
		var can_attack_times = Globals.trial_take_damage(monster, get_final_damage(monster.state))
		var mtween:Tween = monster.create_tween()
		if can_attack_times == -1:
			mtween.set_loops(self.attack_times)
		else:
			mtween.set_loops(can_attack_times + 1)
		mtween.tween_callback(func():
			Shake.shake(monster, 16, 0.2)
		)
		mtween.tween_interval(0.21)
		mtween.tween_callback(func():
			Events.take_damage.emit(player, monster, get_final_damage(monster.state))
		)
			
	var tween := card_view.create_tween()
	tween.tween_interval(self.attack_times * 0.2 + 0.1)
	await tween.finished
	player.play_animation("default")
	card_view.play_on_release_signal_finish.emit()
	

func get_desc() -> String:
	if desc_lab == "":
		return ""
	var text = (
		desc_lab
		% [
			self.attack_times,
			get_final_damage_str()
		]
	)
	return text


func init_from_csv(introduce):
	super.init_from_csv(introduce)
	self.damage = int(introduce[6])
	self.attack_times = int(introduce[5])
